<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page import="db.*,java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Applicants</title>
</head>
<body>
	<%
		// print all applicants
		if (request.getParameter("spec") == null
				&& request.getParameter("disc") == null) {
			ResultSet rs = DBUtil
					.createStatement()
					.executeQuery(
							"SELECT firstName, middleInit, lastName FROM Applicant");
			out.println("<table>");
			while (rs.next()) {
				String fullName = rs.getString(1) + " " + rs.getString(2)
						+ " " + rs.getString(3);
				out.println("<tr>");
				out.println("<td>" + fullName + "<td>");
				out.println("</tr>");
			}
			out.println("</table>");
		}

		// print applicants with specific spec
		if (request.getParameter("spec") != null) {
			int id = Integer.valueOf(request.getParameter("spec"));
			ResultSet rs = DBUtil.createStatement().executeQuery(
					"SELECT firstName, middleInit, lastName FROM Applicant WHERE specID = "
							+ id);
			out.println("<table>");
			while (rs.next()) {
				String fullName = rs.getString(1) + " " + rs.getString(2)
						+ " " + rs.getString(3);
				out.println("<tr>");
				out.println("<td>" + fullName + "<td>");
				out.println("</tr>");
			}
			out.println("</table>");
		}

		// print applicants with specific disc
		if (request.getParameter("disc") != null) {
			int id = Integer.valueOf(request.getParameter("disc"));
			ResultSet rs = DBUtil.createStatement().executeQuery(
					"SELECT DISTINCT(a.id), a.firstName, a.middleInit, a.LastName "
							+ "FROM Applicant a, Degree d "
							+ "WHERE d.disciplineID = " + id
							+ " AND d.studentID = a.id");
			out.println("<table>");
			while (rs.next()) {
				String fullName = rs.getString(2) + " " + rs.getString(3)
						+ " " + rs.getString(4);
				out.println("<tr>");
				out.println("<td>" + fullName + "<td>");
				out.println("</tr>");
			}
			out.println("</table>");
		}
	%>
</body>
</html>